package com.dfrz.planeclub.utill;

import lombok.Data;

import java.util.Map;

@Data
public class BaseResult {

    //响应结果标致 表示接口是否请求成功
    private Boolean success;
    //响应状态码
    private Integer code;
    //状态码描述信息
    private String message;
    //返回的数据
    private Map<String, Object> data;

    //通用返回成功的方法
    public static BaseResult successResult() {
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(ResultCodeEnum.SUCCESS.getSuccess());
        baseResult.setCode(ResultCodeEnum.SUCCESS.getCode());
        baseResult.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        return baseResult;
    }

    //通用返回失败的方法
    public static BaseResult failResult() {
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(ResultCodeEnum.FAILURE.getSuccess());
        baseResult.setCode(ResultCodeEnum.FAILURE.getCode());
        baseResult.setMessage(ResultCodeEnum.FAILURE.getMessage());
        return baseResult;
    }

    //通用系统异常的方法
    public static BaseResult exceptionResult() {
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(ResultCodeEnum.SYSTEM_ERROR.getSuccess());
        baseResult.setCode(ResultCodeEnum.SYSTEM_ERROR.getCode());
        baseResult.setMessage(ResultCodeEnum.SYSTEM_ERROR.getMessage());
        return baseResult;
    }

    public static BaseResult setResult(ResultCodeEnum result, Map<String, Object> data) {
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(result.getSuccess());
        baseResult.setCode(result.getCode());
        baseResult.setMessage(result.getMessage());
        baseResult.setData(data);
        return baseResult;
    }
}
